package cn.ekuma.odbo.mobile.ui.adapter

import android.content.Context
import android.widget.TextView
import cn.ekuma.odbo.mobile.R

open class SampleEntityAdapter<T>(context: Context, entityList:List<T> = mutableListOf(), nullAble: Boolean =false, allAble: Boolean =false) :AbstractEntityAdapter<T,TextView>(context, entityList, R.layout.spinner_entity,nullAble,allAble) {

    override fun displayItemToTextView(textView: TextView, item: T?, position: Int) {
        item?.let{
            if (item is CharSequence) {
                textView.text = item
            } else {
                textView.text = item.toString()
            }
        }
    }

    override fun displaySystemToView(textView: TextView, position: Int) {
        if(position<systemCount)
            textView.text = when {
                position == 0 && nullAble -> "NULL"
                else -> "ALL"
            }
    }
}

open class SampleMapEntityAdapter<T,K>(context: Context,val entityMap:Map<T,K> = mutableMapOf(), nullAble: Boolean =false, allAble: Boolean =false) :AbstractEntityAdapter<Pair<T,K>,TextView>(context, entityMap.toList(), R.layout.spinner_entity,nullAble,allAble) {

    override fun displaySystemToView(textView: TextView, position: Int) {
        if(position<systemCount)
            textView.text = when {
                position == 0 && nullAble -> "NULL"
                else -> "ALL"
            }
    }

    override fun displayItemToTextView(view: TextView, item: Pair<T, K>?, position: Int) {
        item?.let{
            view.text=toString(it.second)
        }
    }

    open fun toString(itemValue:K):String{
       return itemValue.toString()
    }
}